package com.example.nophase.Fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.nophase.R;
import com.example.nophase.activity.ApplyForHomeActivity;
import com.example.nophase.activity.manager.AdultListActivity;
import com.example.nophase.activity.staff.ApplyForListActivity;
import com.example.nophase.activity.staff.StaffMainTaskListActivity;
import com.example.nophase.activity.wageGroup.BatchOfPayActivity;
import com.example.nophase.common.LoginManager;
import com.example.nophase.entity.SysUserVO;

public class ManagerHomeContentFragment extends Fragment {


    public Context context;

    private ManagerHomeContentFragment(Context context) {
        this.context = context;
    }

    public static ManagerHomeContentFragment newInstance(Context context) {
        ManagerHomeContentFragment fragment = new ManagerHomeContentFragment(context);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.manager_home_fragment_content, container, false);
        TextView tv = view.findViewById(R.id.btn_name);
        Button button2 = view.findViewById(R.id.btn_2);
        Button button1 = view.findViewById(R.id.btn_1);
        LinearLayout layout1 = view.findViewById(R.id.btn_1_layout);
        LinearLayout layout2 = view.findViewById(R.id.btn_2_layout);
        SysUserVO userVO = LoginManager.getUserInfo(context);
        String position = userVO.getMoreInfo().getPosition();

        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context, AdultListActivity.class));
            }
        });


        if (userVO.getMoreInfo().isSpecialApp()) {
            button1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivity(new Intent(getActivity(), ApplyForHomeActivity.class));
                }
            });

        } else {
            layout1.setVisibility(View.GONE);
            ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) layout1.getLayoutParams();
            layout1.setRight(0);
            layout1.setLayoutParams(layoutParams);
            ViewGroup.MarginLayoutParams layoutParam2 = (ViewGroup.MarginLayoutParams) layout2.getLayoutParams();
            layout2.setLeft(0);
            layout2.setLayoutParams(layoutParam2);
        }


        return view;
    }
}


